<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>map实现Promise队列</title>
</head>
<body>
    <script>
        // function queue(list){
        //     let promise = Promise.resolve();
        //     list.map(val => {
        //         promise = promise.then(
        //             value => {
        //                 return new Promise((resolve,reject) => {
        //                     setTimeout(() => {
        //                         console.log(val);
        //                         resolve();
        //                     },1000)
        //                 })
        //             }
        //         )
        //     })
        // }

        // queue([1,2,3,4,5]);



        
        function queue1(list){
            let promise = Promise.resolve();
            list.map(val => {
                promise = promise.then(
                    value => val()
                )
            })
        }

        function p1(){
            return new Promise(resolve => {
                setTimeout(() => {
                    console.log('p1');
                    resolve();
                },1000);
            })
        }

        function p2(){
            return new Promise(resolve => {
                setTimeout(() => {
                    console.log('p2');
                    resolve();
                },1000);
            });
        }

        queue1([p1,p2]);
    </script>
</body>
</html>